home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / Shell ƒ / graphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  16.9 KB  |  531 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        graphics.c
  4.  
  5. Purpose:    This module handles opening/closing/updating all windows:
  6.             this includes manipulating offscreen GWorlds & bitmaps
  7.             for fun and profit.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program in a file named "GNU General Public License".
  21. If not, write to the Free Software Foundation, 675 Mass Ave,
  22. Cambridge, MA 02139, USA.
  23.  
  24. \**********************************************************************/
  25.  
  26. #include "graphics.h"
  27. #include "about.h"
  28. #include "about MSG.h"
  29. #include "help.h"
  30. #include "dialogs.h"
  31. #include "error.h"
  32. #include "menus.h"
  33. #include "environment.h"
  34. #include "prefs.h"
  35. #include "util.h"
  36. #include "program globals.h"
  37.  
  38. /* internal global variables for use by graphics.c only */
  39. static    ExtendedWindowDataHandle    gTheWindowData[NUM_WINDOWS];
  40. static    Rect        gBoundsRect[NUM_WINDOWS];        /* rectangle of offscreen bitmap */
  41. static    Rect        gMainScreenBounds;                /* bounds of main monitor */
  42. static    GWorldPtr    gTheGWorld[NUM_WINDOWS];        /* offscreen graphics world */
  43. static    Ptr            gBWBitMap[NUM_WINDOWS];            /* offscreen bitmap for B/W machines */
  44. static    GrafPort    gBWGrafPort[NUM_WINDOWS];        /* offscreen grafport "  "     "     */
  45. static    GrafPtr        gBWGrafPtr[NUM_WINDOWS];        /* offscreen grafptr  "  "     "     */
  46. static    GWorldPtr    currentGWorld;
  47. static    GDHandle    currentGDHandle;
  48.  
  49. Boolean InitTheGraphics(void)
  50. {
  51.     short            i,j;
  52.     
  53.     GetMainScreenBounds();
  54.     
  55.     for (i=0; i<NUM_WINDOWS; i++)
  56.     {
  57.         /* nothing is inited; if there's an error later on, we'll know how much to */
  58.         /* clean up in ShutDownTheGraphics() */
  59.         gTheGWorld[i]=(GWorldPtr)0L;
  60.         gBWGrafPtr[i]=(GrafPtr)0L;
  61.         gBWBitMap[i]=(Ptr)0L;
  62.         gTheWindowData[i]=(ExtendedWindowDataHandle)0L;
  63.     }
  64.     
  65.     for (i=0; i<NUM_WINDOWS; i++)
  66.     {
  67.         gTheWindowData[i]=(ExtendedWindowDataHandle)NewHandle(sizeof(ExtendedWindowDataRec));
  68.         if (gTheWindowData[i]==0L)                            /* return if error */
  69.             return FALSE;
  70.         
  71.         (**(gTheWindowData[i])).offscreenNeedsUpdate=TRUE;    /* offscreen not inited */
  72.         (**(gTheWindowData[i])).theWindowPtr=0L;            /* window ptr not inited */
  73.         (**(gTheWindowData[i])).windowIndex=i;                /* so we can retrieve it O(1) */
  74.         (**(gTheWindowData[i])).windowDepth=
  75.             (**(gTheWindowData[i])).maxDepth=1;                /* init at B/W */
  76.         (**(gTheWindowData[i])).isColor=FALSE;                /* init to grayscale */
  77.         for (j=0; j<MAX_TE_HANDLES; j++)
  78.             (**(gTheWindowData[i])).hTE[j]=0L;
  79.         HLockHi((Handle)gTheWindowData[i]);
  80.     }
  81.     
  82.     /* set window dispatch routines */
  83.     SetIndDispatchProc(kAbout, AboutBoxDispatch);
  84.     SetIndDispatchProc(kHelp, HelpWindowDispatch);
  85.     SetIndDispatchProc(kAboutMSG, AboutMSGBoxDispatch);
  86.     
  87.     /* call window dispatch routines with "startup" message */
  88.     CallIndDispatchProc(kAbout, kStartup, 0L);
  89.     CallIndDispatchProc(kAboutMSG, kStartup, 0L);
  90.     
  91.     return TRUE;
  92. }
  93.  
  94. void OpenTheIndWindow(short index)
  95. {
  96.     WindowPtr        theWindow;
  97.     
  98.     if (!((**gTheWindowData[index]).theWindowPtr))        /* if window exists, we'll just update it (see below) */
  99.     {
  100.         if (CallIndDispatchProc(index, kInitialize, 0L)==kFailure)
  101.         {        /* default is to center window on main screen */
  102.             (**(gTheWindowData[index])).initialTopLeft.h =
  103.                 gMainScreenBounds.left + (((gMainScreenBounds.right -
  104.                 gMainScreenBounds.left) - (**(gTheWindowData[index])).windowWidth) / 2);
  105.             (**(gTheWindowData[index])).initialTopLeft.v =
  106.                 gMainScreenBounds.top + (((gMainScreenBounds.bottom -
  107.                 gMainScreenBounds.top) - (**(gTheWindowData[index])).windowHeight) / 2);
  108.         }
  109.         
  110.         (**(gTheWindowData[index])).windowBounds.left=
  111.             (**(gTheWindowData[index])).initialTopLeft.h;
  112.         
  113.         (**(gTheWindowData[index])).windowBounds.top=
  114.             (**(gTheWindowData[index])).initialTopLeft.v;
  115.             
  116.         if (((**(gTheWindowData[index])).windowType==noGrowDocProc) ||
  117.             ((**(gTheWindowData[index])).windowType==documentProc) ||
  118.             ((**(gTheWindowData[index])).windowType==movableDBoxProc) ||
  119.             ((**(gTheWindowData[index])).windowType==zoomDocProc) ||
  120.             ((**(gTheWindowData[index])).windowType==zoomNoGrow) ||
  121.             ((**(gTheWindowData[index])).windowType==rDocProc))
  122.                 (**(gTheWindowData[index])).windowBounds.top += 9;    /* compensate for title */
  123.         
  124.         /* don't put window over menu bar */
  125.         if ((**(gTheWindowData[index])).windowBounds.top < GetMBarHeight()+1)
  126.             (**(gTheWindowData[index])).windowBounds.top = GetMBarHeight()+1;
  127.         
  128.         (**(gTheWindowData[index])).windowBounds.bottom =
  129.             (**(gTheWindowData[index])).windowBounds.top +
  130.             (**(gTheWindowData[index])).windowHeight;
  131.         
  132.         (**(gTheWindowData[index])).windowBounds.right =
  133.             (**(gTheWindowData[index])).windowBounds.left +
  134.             (**(gTheWindowData[index])).windowWidth;
  135.         
  136.         KillOffscreen(index);        /* kill offscreen bitmaps that are left over */
  137.         
  138.         if (gHasColorQD)
  139.         {
  140.             /* create the color window with our specs, see IM Essentials 4-79ff */
  141.             (**gTheWindowData[index]).theWindowPtr=
  142.                 NewCWindow(0L, &((**(gTheWindowData[index])).windowBounds),
  143.                 (**(gTheWindowData[index])).windowTitle, FALSE,
  144.                 (**(gTheWindowData[index])).windowType, (WindowPtr)-1L,
  145.                 (**(gTheWindowData[index])).hasCloseBox,
  146.                 (unsigned long)gTheWindowData[index]);
  147.         }
  148.         else
  149.         {
  150.             /* create the B/W window with our specs, see IM Essentials 4-82ff */
  151.             (**gTheWindowData[index]).theWindowPtr=
  152.                 NewWindow(0L, &((**(gTheWindowData[index])).windowBounds),
  153.                 (**(gTheWindowData[index])).windowTitle, FALSE,
  154.                 (**(gTheWindowData[index])).windowType, (WindowPtr)-1L,
  155.                 (**(gTheWindowData[index])).hasCloseBox,
  156.                 (unsigned long)gTheWindowData[index]);
  157.         }
  158.     }
  159.     
  160.     if ((theWindow=GetIndWindowGrafPtr(index))!=0L)
  161.     {
  162.         ShowWindow(theWindow);            /* immediately show this new window */
  163.         SelectWindow(theWindow);        /* immediately select this new window */
  164.         SetPort(theWindow);            /* important! for TE info to stick*/
  165.         /* call window's dispatch routine to alert it that it's open now */
  166.         CallIndDispatchProc(index, kOpen, 0L);
  167.         UpdateTheWindow((ExtendedWindowDataHandle)gTheWindowData[index]);    /* immediately update this new window */
  168.     }
  169.     else HandleError(kNoMemory, FALSE);            /* if unsuccessful, display error */
  170. }
  171.  
  172. void GetMainScreenBounds(void)
  173. {
  174.     gMainScreenBounds = screenBits.bounds;        /* low-mem global */
  175.     gMainScreenBounds.top += GetMBarHeight();    /* don't include menu bar */
  176. }
  177.  
  178. short GetBiggestDeviceDepth(ExtendedWindowDataHandle theData)
  179. {
  180.     short            index;
  181.     Rect            tempRect;
  182.     long            biggestSize;
  183.     long            tempSize;
  184.     GDHandle        thisHandle, gBiggestDevice;
  185.     
  186.     if (!gHasColorQD)
  187.         return 1;
  188.     
  189.     index=(**theData).windowIndex;
  190.     
  191.     if (!GetIndWindowGrafPtr(index))
  192.         return (**(**GetMainDevice()).gdPMap).pixelSize;
  193.     
  194.     thisHandle = GetDeviceList();
  195.     gBiggestDevice = 0L;
  196.     biggestSize = 0L;
  197.     
  198.     while (thisHandle)
  199.     {
  200.         if (TestDeviceAttribute(thisHandle, screenDevice) &&
  201.             TestDeviceAttribute(thisHandle, screenActive))
  202.         {
  203.             if (SectRect(&(GetIndWindowGrafPtr(index)->portRect), &((**thisHandle).gdRect),
  204.                     &tempRect))
  205.             {
  206.                 if (biggestSize < (tempSize = ((long)(tempRect.bottom - tempRect.top))*
  207.                     ((long)(tempRect.right - tempRect.left))))
  208.                 {
  209.                     biggestSize = tempSize;
  210.                     gBiggestDevice = thisHandle;
  211.                 }
  212.             }
  213.         }
  214.         thisHandle = GetNextDevice(thisHandle);
  215.     }
  216.     
  217.     return (gBiggestDevice) ? (**(**gBiggestDevice).gdPMap).pixelSize : 1;
  218. }
  219.  
  220. short GetWindowDepth(ExtendedWindowDataHandle theData)
  221. {
  222.     short            index;
  223.     
  224.     index=(**theData).windowIndex;
  225.     /* if Color Quickdraw is not available, the depth must be 1. */
  226.     /* if Color Quickdraw is available and the window exists, return the window's
  227.        GWorld's graphics device's pixel map's pixel depth */
  228.     /* if Color Quickdraw is available and the window does not exist, return the
  229.        pixel depth of the main screen */
  230.     return (gHasColorQD) ? ((GetIndWindowGrafPtr(index)) ?
  231.             (**(**(GetGWorldDevice(gTheGWorld[index]))).gdPMap).pixelSize :
  232.             (**(**GetMainDevice()).gdPMap).pixelSize) : 1;
  233. }
  234.  
  235. Boolean WindowIsColor(ExtendedWindowDataHandle theData)
  236. {
  237.     short            index;
  238.     
  239.     index=(**theData).windowIndex;
  240.     return (gHasColorQD) ? ((GetWindowDepth(theData)>8) ? TRUE :
  241.         TestDeviceAttribute(GetGWorldDevice(gTheGWorld[index]), gdDevType)) : FALSE;
  242. }
  243.  
  244. void UpdateTheWindow(ExtendedWindowDataHandle theData)
  245. {
  246.     short            index;
  247.     long            offRowBytes, sizeOfOff;
  248.     unsigned long    updateResult;
  249.     Boolean            isColor;
  250.     PixMapHandle    thePixMapHandle;
  251.     short            teIter;
  252.     
  253.     index=(**theData).windowIndex;
  254.     gBoundsRect[index]=GetIndWindowGrafPtr(index)->portRect;
  255.     OffsetRect(&gBoundsRect[index], -gBoundsRect[index].left, -gBoundsRect[index].top);
  256.  
  257.     if (gHasColorQD)    /* w/o Color Quickdraw, GWorlds may not be supported */
  258.     {
  259.         if (gTheGWorld[index]==0L)        /* create new graphics world if none exists */
  260.         {
  261.             /* try to create new graphics world; display error if unsuccessful */
  262.             if (NewGWorld(&gTheGWorld[index],
  263.                 (GetBiggestDeviceDepth(theData)>=(**theData).maxDepth) ?
  264.                 (**theData).maxDepth : 0, &gBoundsRect[index], 0L, 0L, 0)!=0)
  265.             {
  266.                 HandleError(kNoMemory, TRUE);        /* quits */
  267.             }
  268.             
  269.             (**theData).windowDepth=GetWindowDepth(theData);
  270.             NoPurgePixels(GetGWorldPixMap(gTheGWorld[index]));    /* never purge our pixmap! */
  271.             updateResult=1;
  272.         }
  273.         else updateResult=0;
  274.         
  275.         GetGWorld(¤tGWorld, ¤tGDHandle);    /* get current settings */
  276.         LockPixels(thePixMapHandle=GetGWorldPixMap(gTheGWorld[index]));    /* important!  copybits may move mem */
  277.         /* update offscreen graphics world, compensating for change in pixel depth */
  278.         updateResult|=(unsigned long)UpdateGWorld(&gTheGWorld[index],
  279.             (GetBiggestDeviceDepth(theData)>=(**theData).maxDepth) ? (**theData).maxDepth :
  280.             0, &gBoundsRect[index], 0L, 0L, 0);
  281.         SetGWorld(gTheGWorld[index], 0L);                /* set to our offscreen gworld */
  282.         
  283.         isColor=WindowIsColor(theData);
  284.         if (isColor!=(**theData).isColor)
  285.         {
  286.             (**theData).isColor=isColor;
  287.             updateResult=1;
  288.         }
  289.         
  290.         if ((updateResult!=0L) || ((**theData).windowDepth!=GetWindowDepth(theData)))
  291.         {
  292.             (**theData).windowDepth=GetWindowDepth(theData);    /* save new depth */
  293.             (**theData).offscreenNeedsUpdate=TRUE;                /* we'll need to redraw */
  294.             CallDispatchProc(theData, kChangeDepth, 0L);
  295.         }
  296.     }
  297.     else    /* deal with (guaranteed) B/W bitmaps manually */
  298.     {
  299.         if (gBWGrafPtr[index]==0L)    /* create new offscreen bitmap if none exists */
  300.         {
  301.             gBWGrafPtr[index]=&gBWGrafPort[index];
  302.             OpenPort(gBWGrafPtr[index]);    /* make a new port */
  303.             
  304.             /* calculate the size of the offscreen bitmap from the boundsrect */
  305.             offRowBytes=(((gBoundsRect[index].right-gBoundsRect[index].left)+15)>>4)<<1;
  306.             sizeOfOff=(long)(gBoundsRect[index].bottom-gBoundsRect[index].top)*offRowBytes;
  307.             
  308.             gBWBitMap[index]=NewPtr(sizeOfOff);        /* allocate space for bitmap */
  309.             if (gBWBitMap[index]==0L)                /* abort if unsuccessful */
  310.             {
  311.                 ClosePort(gBWGrafPtr[index]);        /* cleaning up... */
  312.                 gBWGrafPtr[index]=0L;
  313.                 HandleError(kNoMemory, TRUE);        /* displaying error... */
  314.             }
  315.             
  316.             gBWGrafPort[index].portBits.baseAddr=gBWBitMap[index];    /* --> our bitmap */
  317.             gBWGrafPort[index].portBits.rowBytes=offRowBytes;        /* bitmap size */
  318.             gBWGrafPort[index].portBits.bounds=                        /* bitmap bounds */
  319.                 gBWGrafPort[index].portRect=gBoundsRect[index];
  320.             
  321.             SetPort(gBWGrafPtr[index]);
  322.             (**theData).offscreenNeedsUpdate=TRUE;
  323.         }
  324.         else SetPort(gBWGrafPtr[index]);            /* set port for subsequent drawing */
  325.     }    
  326.     
  327.     if ((**theData).offscreenNeedsUpdate)            /* if we need to redraw */
  328.     {
  329.         (**theData).offscreenNeedsUpdate=FALSE;        /* not anymore */
  330.         /* call window's dispatch and tell it to redraw itself */
  331.         CallDispatchProc(theData, kUpdate, GetWindowDepth(theData));
  332.     }
  333.     
  334.     if (gHasColorQD)
  335.         SetGWorld(currentGWorld, currentGDHandle);    /* restore old settings */
  336.     
  337.     SetPort(GetWindowGrafPtr((WindowDataHandle)theData));
  338.     
  339.     /* copy offscreen bitmap from graphics world or bitmap to onscreen window */
  340.     if (CallDispatchProc(theData, kCopybits, gHasColorQD ? (unsigned long)gTheGWorld[index] :
  341.         (unsigned long)gBWGrafPtr[index])==kFailure)
  342.         CopyBits(gHasColorQD ? &(((GrafPtr)gTheGWorld[index])->portBits) :
  343.                     &(gBWGrafPtr[index]->portBits), &(GetIndWindowGrafPtr(index)->portBits),
  344.                     &gBoundsRect[index], &gBoundsRect[index], 0, 0L);
  345.     
  346.     for (teIter=0; teIter<MAX_TE_HANDLES; teIter++)
  347.     {
  348.         if ((**theData).hTE[teIter]!=0L)
  349.             TEUpdate(&(GetIndWindowGrafPtr(index)->portRect), (**theData).hTE[teIter]);
  350.     }
  351.  
  352.     if (gHasColorQD)
  353.         UnlockPixels(thePixMapHandle);    /* remember we locked these? */
  354.     
  355.     ValidRect(&(GetIndWindowGrafPtr(index)->portRect));        /* so we don't reupdate */
  356.     
  357.     if (index!=kHelp)
  358.         KillOffscreen(index);
  359. }
  360.  
  361. Boolean CloseTheWindow(ExtendedWindowDataHandle theData)
  362. {
  363.     short            index;
  364.     
  365.     index=(**theData).windowIndex;
  366.     
  367.     /* if the window's dispatch cancels the close, abort */
  368.     if (CallDispatchProc(theData, kClose, 0L)==kCancel)
  369.         return FALSE;
  370.     
  371.     DisposeWindow(GetIndWindowGrafPtr(index));    /* get rid of the actual window in memory */
  372.     (**gTheWindowData[index]).theWindowPtr=0L;    /* so _we_ know the window doesn't exist */
  373.     KillOffscreen(index);                /* kill offscreen bitmaps left over */
  374.     
  375.     /* tell window's dispatch that it's disposed of now */
  376.     CallDispatchProc(theData, kDispose, 0L);
  377.     
  378.     return TRUE;    /* successful close */
  379. }
  380.  
  381. Boolean CloseTheIndWindow(short index)
  382. {
  383.     return CloseTheWindow(gTheWindowData[index]);
  384. }
  385.  
  386. PicHandle DrawThePicture(PicHandle thePict, short whichPict, short x, short y,
  387.     Boolean isCentered)
  388. /* a standard routine for loading a picture (if necessary) and then drawing it */
  389. {
  390.     Rect            temp;
  391.     
  392.     if (thePict==0L)        /* get it if it doesn't exist */
  393.         thePict=(PicHandle)GetPicture(whichPict);
  394.     
  395.     HLock((Handle)thePict);        /* lock it down for dereferencing to get picture bounds */
  396.     temp.top=y;
  397.     temp.left=x;
  398.     temp.bottom=temp.top+(**thePict).picFrame.bottom-(**thePict).picFrame.top;
  399.     temp.right=temp.left+(**thePict).picFrame.right-(**thePict).picFrame.left;
  400.     if (isCentered)
  401.     {
  402.         OffsetRect(&temp, -(temp.right-temp.left)/2, -(temp.bottom-temp.top)/2);
  403.     }
  404.     DrawPicture(thePict, &temp);    /* draw picture at (x,y) */
  405.     HUnlock((Handle)thePict);        /* unlock for better memory management */
  406.     return thePict;
  407. }
  408.  
  409. PicHandle ReleaseThePict(PicHandle thePict)
  410. {
  411.     if (thePict!=0L)    /* if exists, release it */
  412.         ReleaseResource((Handle)thePict);
  413.     return 0L;
  414. }
  415.  
  416. Boolean SetPortToOffscreen(WindowDataHandle theData)
  417. {
  418.     short            index;
  419.     
  420.     index=(**theData).windowIndex;
  421.     
  422.     if (gHasColorQD)
  423.     {
  424.         if (gTheGWorld[index]==0L)
  425.             return FALSE;
  426.         GetGWorld(¤tGWorld, ¤tGDHandle);    /* get current settings */
  427.         LockPixels(GetGWorldPixMap(gTheGWorld[index]));    /* important!  copybits may move mem */
  428.         SetGWorld(gTheGWorld[index], 0L);
  429.     }
  430.     else
  431.     {
  432.         if (gBWGrafPtr[index]==0L)
  433.             return FALSE;
  434.         SetPort(gBWGrafPtr[index]);
  435.     }
  436.     
  437.     return TRUE;
  438. }
  439.  
  440. void RestorePortToScreen(WindowDataHandle theData)
  441. {
  442.     if (gHasColorQD)
  443.     {
  444.         SetGWorld(currentGWorld, currentGDHandle);    /* restore old settings */
  445.         UnlockPixels(GetGWorldPixMap(gTheGWorld[(**theData).windowIndex]));
  446.     }
  447.     
  448.     SetPort(GetWindowGrafPtr(theData));
  449. }
  450.  
  451. GrafPtr GetOffscreenGrafPtr(WindowDataHandle theData)
  452. {
  453.     if (gHasColorQD)
  454.         return (GrafPtr)gTheGWorld[(**theData).windowIndex];
  455.     else
  456.         return gBWGrafPtr[(**theData).windowIndex];
  457. }
  458.  
  459. GrafPtr GetIndOffscreenGrafPtr(short index)
  460. {
  461.     return GetOffscreenGrafPtr((WindowDataHandle)gTheWindowData[index]);
  462. }
  463.  
  464. GrafPtr GetWindowGrafPtr(WindowDataHandle theData)
  465. {
  466.     return (GrafPtr)((**theData).theWindowPtr);
  467. }
  468.  
  469. GrafPtr GetIndWindowGrafPtr(short index)
  470. {
  471.     return GetWindowGrafPtr((WindowDataHandle)gTheWindowData[index]);
  472. }
  473.  
  474. ExtendedWindowDataHandle GetIndWindowDataHandle(short index)
  475. {
  476.     return gTheWindowData[index];
  477. }
  478.  
  479. void SetIndDispatchProc(short index, ProcPtr theProc)
  480. {
  481.     (**gTheWindowData[index]).dispatchProc=theProc;
  482. }
  483.  
  484. short CallIndDispatchProc(short index, short theMessage, unsigned long misc)
  485. {
  486.     return ((**(gTheWindowData[index])).dispatchProc)((WindowDataHandle)gTheWindowData[index], theMessage, misc);
  487. }
  488.  
  489. short CallDispatchProc(ExtendedWindowDataHandle theData, short theMessage, unsigned long misc)
  490. {
  491.     return ((**theData).dispatchProc)((WindowDataHandle)theData, theMessage, misc);
  492. }
  493.  
  494. void SetIndWindowTitle(short index, Str255 theTitle)
  495. {
  496.     Mymemcpy((Ptr)((**(gTheWindowData[index])).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  497. }
  498.  
  499. void KillOffscreen(short index)
  500. {
  501.     if (gTheGWorld[index]!=0L)
  502.         DisposeGWorld(gTheGWorld[index]);
  503.     if (gBWGrafPtr[index]!=0L)
  504.     {
  505.         DisposePtr((Ptr)gBWGrafPtr[index]);
  506.         DisposePtr(gBWBitMap[index]);
  507.     }
  508.     gTheGWorld[index]=0L;
  509.     gBWGrafPtr[index]=0L;
  510.     (**(gTheWindowData[index])).offscreenNeedsUpdate=TRUE;
  511. }
  512.  
  513. void ShutDownTheGraphics(void)
  514. {
  515.     short            i;
  516.     
  517.     /* send shutdown messages to the shell's windows */
  518.     CallIndDispatchProc(kAbout, kShutdown, 0L);
  519.     CallIndDispatchProc(kHelp, kShutdown, 0L);
  520.     CallIndDispatchProc(kAboutMSG, kShutdown, 0L);
  521.     
  522.     for (i=0; i<NUM_WINDOWS; i++)
  523.     {
  524.         KillOffscreen(i);
  525.         if (GetIndWindowGrafPtr(i)!=0L)
  526.             DisposeWindow((**gTheWindowData[i]).theWindowPtr);
  527.         if (gTheWindowData[i]!=0L)
  528.             DisposeHandle((Handle)gTheWindowData[i]);
  529.     }
  530. }
  531.